package net.vkits.api;

import io.jsonwebtoken.Claims;
import io.swagger.annotations.ApiParam;
import net.vkits.anjiamiao.application.FeedbackApplicationService;
import net.vkits.common.dto.BaseDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by ethan-liu on 2017/1/6.
 */

@Controller
public class FeedbackApiController implements FeedbackApi {
    private static final Logger logger = LoggerFactory.getLogger(FeedbackApiController.class);

    @Resource
    private HttpServletRequest request;
    @Resource
    private FeedbackApplicationService feedbackApplicationService;

    @Override
    public ResponseEntity<BaseDTO> feedback(@ApiParam(value = "反馈信息", required = true) @RequestParam String content) {
        final Claims claims = (Claims) request.getAttribute("claims");
        String cellphone = claims.get("phone").toString();
        feedbackApplicationService.submitFeedback(content, cellphone);
        BaseDTO baseDTO = new BaseDTO();
        baseDTO.setCode(200);
        baseDTO.setMsg("OK");
        return new ResponseEntity<>(baseDTO, HttpStatus.OK);
    }
}
